package com.uuuo.mvp.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by JiaTao on 2018/8/30.
 * Email: 535318720@qq.com
 * Version: 1.0
 * Description:
 */
public abstract class BaseMVPActivity<P extends BasePresenter> extends AppCompatActivity implements IBaseView {
    private P mPresenter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView();

        // 创建 P，创建只能交给 子类，每个 Activity 都不一样
        mPresenter = createPresenter();
        // 绑定View到Presenter
        mPresenter.attach(this);

        initView();
        initData();
    }

    // 由子类去实现创建
    protected abstract void setContentView();

    protected abstract P createPresenter();

    protected abstract void initView();

    protected abstract void initData();


    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detach();
    }

    public P getPresenter() {
        return mPresenter;
    }
}
